﻿<% @ LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<% Option Explicit %>
<%
    Dim Result, FormAddress, ToAddress, MailBody, MailSubject
    Dim Language
    Dim ld_cName, ld_pName, ld_Tel, ld_Mail, ld_Class
    Dim mb1_cName, mb1_pName, mb1_Tel, mb1_Mail, mb1_Class
    Dim mb2_cName, mb2_pName, mb2_Tel, mb2_Mail, mb2_Class
    Dim mb3_cName, mb3_pName, mb3_Tel, mb3_Mail, mb3_Class
    Dim scl_Name, tc_cName, tc_pName, tc_Tel, tc_Mail, notify
    Dim currentDate, dealineDate, activeDays, expired

    currentDate = FormatDateTime(Now(),2)
    dealineDate = "2011/1/9"

    activeDays = DateDiff("d",currentDate,dealineDate)

    If activeDays < 1 Then
        Response.Write("The page is expired")
    Else
        notify = Request.QueryString("notify")
        ld_cName = Request.QueryString("ld_cname")
        ld_pName = Request.QueryString("ld_pname")
        ld_Tel = Request.QueryString("ld_tel")
        ld_Mail = Request.QueryString("ld_mail")
        ld_Class = Request.QueryString("ld_class")
        mb1_cName = Request.QueryString("mb1_cname")
        mb1_pName = Request.QueryString("mb1_pname")
        mb1_Tel = Request.QueryString("mb1_tel")
        mb1_Mail = Request.QueryString("mb1_mail")
        mb1_Class = Request.QueryString("mb1_class")
        mb2_cName = Request.QueryString("mb2_cname")
        mb2_pName = Request.QueryString("mb2_pname")
        mb2_Tel = Request.QueryString("mb2_tel")
        mb2_Mail = Request.QueryString("mb2_mail")
        mb2_Class = Request.QueryString("mb2_class")
        mb3_cName = Request.QueryString("mb3_cname")
        mb3_pName = Request.QueryString("mb3_pname")
        mb3_Tel = Request.QueryString("mb3_tel")
        mb3_Mail = Request.QueryString("mb3_mail")
        mb3_Class = Request.QueryString("mb3_class")
        scl_Name = Request.QueryString("scl_name")
        tc_cName = Request.QueryString("tc_cname")
        tc_pName = Request.QueryString("tc_pname")
        tc_Tel = Request.QueryString("tc_tel")
        tc_Mail = Request.QueryString("tc_mail")
    
        Language = Request.QueryString("language")
        FormAddress = "webmaster@macao.communications.museum"
        ToAddress = "info@macao.communications.museum"

        MailBody = getMailBody(Language)
        MailSubject = getMailText("MAIL_SUBJECT", Language)
        Result = sendMail(MailBody, MailSubject, FormAddress, ToAddress)
        Response.Flush
        'Response.Write(MailBody)
    End If
%>

<%
Function getMailBody(lang)
    Dim m
    Response.CharSet = "utf-8"
    m = "<html xmlns='http://www.w3.org/1999/xhtml'>"
    m = m & "<head>"
    m = m & "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"
    m = m & "<title></title>"
    m = m & "<style type='text/css'>"
    m = m & "table  {border-collapse: collapse; border-left: 1px solid black; border-top: 1px solid black;}"
    m = m & "th, td {text-align: center; border-bottom: 1px solid black; border-right: 1px solid black; padding: 5px;}"
    m = m & "</style>"
    m = m & "</head>"
    m = m & "<body>"
    If notify = "agree" Then
        m = m & "<p>" & getMailText("ACCEPT_AGREEMENT",lang) &"</p>"
    Else
        m = m & "<p>" & getMailText("REJECT_AGREEMENT",lang) &"</p>" 
    End If
    m = m & "<table>"
    m = m & "<caption>" & getMailText("FORM_TITLE", lang) & "</caption>"
    m = m & "<tr>"
    m = m & "<th colspan='6'>" & getMailText("STUDENT_INFO", lang) & "</tr>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th rowspan='2'></th>"
    m = m & "<th colspan='2'>" & getMailText("STUDENT_NAME", lang) & "</th>"
    m = m & "<th colspan='2'>" & getMailText("CONTACT_INFO", lang) & "</th>"
    m = m & "<th rowspan='2'>" & getMailText("GRADE", lang) & "</th>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th>" & getMailText("CHI_NAME", lang) & "</th>"
    m = m & "<th>" & getMailText("POR_NAME", lang) & "</th>"
    m = m & "<th>" & getMailText("TEL", lang) & "</th>"
    m = m & "<th>" & getMailText("EMAIL", lang) & "</th>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th>" & getMailText("LEADER_NAME", lang) & "</th>"
    m = m & "<td>" & ld_cName & "</td>"
    m = m & "<td>" & ld_pName & "</td>"
    m = m & "<td>" & ld_Tel & "</td>"
    m = m & "<td>" & ld_Mail & "</td>"
    m = m & "<td>" & ld_Class & "</td>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th>" & getMailText("MEMBER1_NAME", lang) & "</th>"
    m = m & "<td>" & mb1_cName & "</td>"
    m = m & "<td>" & mb1_pName & "</td>"
    m = m & "<td>" & mb1_Tel & "</td>"
    m = m & "<td>" & mb1_Mail & "</td>"
    m = m & "<td>" & mb1_Class & "</td>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th>" & getMailText("MEMBER2_NAME", lang) & "</th>"
    m = m & "<td>" & mb2_cName & "</td>"
    m = m & "<td>" & mb2_pName & "</td>"
    m = m & "<td>" & mb2_Tel & "</td>"
    m = m & "<td>" & mb2_Mail & "</td>"
    m = m & "<td>" & mb2_Class & "</td>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th>" & getMailText("MEMBER3_NAME", lang) & "</th>"
    m = m & "<td>" & mb3_cName & "</td>"
    m = m & "<td>" & mb3_pName & "</td>"
    m = m & "<td>" & mb3_Tel & "</td>"
    m = m & "<td>" & mb3_Mail & "</td>"
    m = m & "<td>" & mb3_Class & "</td>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th colspan='6'>" & getMailText("SCHOOL_INFO", lang) & "</tr>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th>" & getMailText("SCHOOL_NAME", lang) & "</th>"
    m = m & "<td colspan='5'>" & scl_Name & "</td>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th rowspan='2'>" & getMailText("TEACHER_NAME", lang) & "</th>"
    m = m & "<th>" & getMailText("TEACHER_CNAME", lang) & "</th>"
    m = m & "<td colspan='4'>" & tc_cName & "</td>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th>" & getMailText("TEACHER_PNAME", lang) & "</th>"
    m = m & "<td colspan='4'>" & tc_pName & "</td>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th rowspan='2'>" & getMailText("TEACHER_CONTACT", lang) & "</th>"
    m = m & "<th>" & getMailText("TEACHER_TEL", lang) & "</th>"
    m = m & "<td colspan='4'>" & tc_TEL & "</td>"
    m = m & "</tr>"
    m = m & "<tr>"
    m = m & "<th>" & getMailText("TEACHER_MAIL", lang) & "</th>"
    m = m & "<td colspan='4'>" & tc_MAIL & "</td>"
    m = m & "</tr>"
    m = m & "</table>"
    m = m & "</body>"
    m = m & "</html>"
    getMailBody = m
End Function

Function sendMail(HtmlBody, Subject, FromAddress, ToAddress)
  Dim myMail, ServerName
  ServerName = Request.ServerVariables("SERVER_NAME")
  Set myMail = CreateObject("CDO.Message")
  myMail.Subject = Subject
  'if FromAddress="" Then
	'FromAddress = Chr(34) & Request.Form("email") & Chr(34) & " <shlei@macaupost.gov.mo>"
  'End If
  'if Request.Form("email")<>"" then
     ' myMail.Fields.Item("urn:schemas:mailheader:Reply-To")=Request.Form("email")
     'myMail.ReplyTo=Request.Form("email")
  'end if
  myMail.From = FromAddress 
  myMail.BodyPart.CharSet = "utf-8"
  myMail.To = ToAddress
  'MyMail.Bcc="webmaster@macao.communications.museum"
  myMail.HtmlBody = HtmlBody
  If ServerName = "localhost" Then
  'For local test
  myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.10.12"
  Else
  'For Web host
  myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.215.186"
  End If
  myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
  'myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  'myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "info@macao.communications.museum"
  'myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "info0621"
  myMail.Configuration.Fields.Update
  myMail.Send
  Set myMail = Nothing
  SendMail = True
End function

Function getMailText(Caption, Language)
    getMailText = ""
    Select Case Caption
        Case "MAIL_SUBJECT"
            Select Case Language
                Case "chi"
                    getMailText = "2011年度通訊博物館電子裝置製作比賽報名表格 - " & scl_Name & " - " & ld_cName 
                Case "chis"
                    getMailText = "2011年度通讯博物馆电子装置制作比赛报名表格 - " & scl_Name & " - " & ld_cName
                Case "eng"
                    getMailText = "2011 Communications Museum Electronic Device Construction Competition(Registration Form) - " & scl_Name & " - " & ld_pName
                Case "por"
                    getMailText = "Museu das Comunicações 2011 - Concurso de Construção de Dispositivos Electrónicos(Ficha de Inscrição) - " & scl_Name & " - " & ld_pName
            End Select
        Case "FORM_TITLE"
            Select Case Language
                Case "chi"
                    getMailText = "2011年度通訊博物館電子裝置製作比賽報名表格" 
                Case "chis"
                    getMailText = "2011年度通讯博物馆电子装置制作比赛报名表格"
                Case "eng"
                    getMailText = "2011 Communications Museum Electronic Device Construction Competition(Registration Form)"
                Case "por"
                    getMailText = "Museu das Comunicações 2011 - Concurso de Construção de Dispositivos Electrónicos(Ficha de Inscrição)"
            End Select
        Case "ACCEPT_AGREEMENT"
            Select Case Language
                Case "chi"
                    getMailText = "本人<strong>願意</strong>在日後收到通訊博物館的服務或活動宣傳通知。" 
                Case "chis"
                    getMailText = "本人<strong>愿意</strong>在日后收到通讯博物馆的服务或活动宣传通知。"
                Case "eng"
                    getMailText = "Applicant <strong>wants</strong> to receive promotional information from Communications Museum."
                Case "por"
                    getMailText = "Requerente <strong>quer</strong> receber informação promocional do Museu das Comunicações."
            End Select
        Case "REJECT_AGREEMENT"
            Select Case Language
                Case "chi"
                    getMailText = "本人<strong>不願意</strong>在日後收到通訊博物館的服務或活動宣傳通知。" 
                Case "chis"
                    getMailText = "本人<strong>不愿意</strong>在日后收到通讯博物馆的服务或活动宣传通知。"
                Case "eng"
                    getMailText = "Applicant <strong>does not want</strong> to receive promotional information from Communications Museum."
                Case "por"
                    getMailText = "Requerente <strong>não quer</strong> receber informação promocional do Museu das Comunicações."
            End Select
        Case "STUDENT_INFO"
            Select Case Language
                Case "chi"
                    getMailText = "參賽學生資料" 
                Case "chis"
                    getMailText = "参赛学生资料"
                Case "eng"
                    getMailText = "Personal Picture Postcard"
                Case "por"
                    getMailText = "Informação dos Participants"
            End Select
        Case "STUDENT_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "學生姓名" 
                Case "chis"
                    getMailText = "学生姓名"
                Case "eng"
                    getMailText = "Name of Students"
                Case "por"
                    getMailText = "Nome do(s) Estudante(s)"
            End Select
        Case "CHI_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "中文姓名" 
                Case "chis"
                    getMailText = "中文姓名"
                Case "eng"
                    getMailText = "Name in Chinese"
                Case "por"
                    getMailText = "Nome em Chinês"
            End Select
        Case "POR_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "葡文姓名 (證件上拼音)" 
                Case "chis"
                    getMailText = "葡文姓名 (证件上拼音)"
                Case "eng"
                    getMailText = "Name in Portugues"
                Case "por"
                    getMailText = "Nome em Português"
            End Select
        Case "CONTACT_INFO"
            Select Case Language
                Case "chi"
                    getMailText = "聯絡方法" 
                Case "chis"
                    getMailText = "联络方法"
                Case "eng"
                    getMailText = "Contact Information"
                Case "por"
                    getMailText = "Contactos"
            End Select
        Case "TEL"
            Select Case Language
                Case "chi"
                    getMailText = "電話" 
                Case "chis"
                    getMailText = "电话"
                Case "eng"
                    getMailText = "Tel."
                Case "por"
                    getMailText = "Telefone"
            End Select
        Case "EMAIL"
            Select Case Language
                Case "chi"
                    getMailText = "電郵" 
                Case "chis"
                    getMailText = "电邮"
                Case "eng"
                    getMailText = "E-Mail"
                Case "por"
                    getMailText = "E-Mail"
            End Select
        Case "GRADE"
            Select Case Language
                Case "chi"
                    getMailText = "年級" 
                Case "chis"
                    getMailText = "年级"
                Case "eng"
                    getMailText = "Grade"
                Case "por"
                    getMailText = "Ano"
            End Select
        Case "LEADER_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "組長" 
                Case "chis"
                    getMailText = "组长"
                Case "eng"
                    getMailText = "Leader"
                Case "por"
                    getMailText = "Líder"
            End Select
        Case "MEMBER1_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "組員一" 
                Case "chis"
                    getMailText = "组员一"
                Case "eng"
                    getMailText = "Member (1)"
                Case "por"
                    getMailText = "Membro (1)"
            End Select
        Case "MEMBER2_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "組員二" 
                Case "chis"
                    getMailText = "组员二"
                Case "eng"
                    getMailText = "Member (2)"
                Case "por"
                    getMailText = "Membro (2)"
            End Select
        Case "MEMBER3_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "組員三" 
                Case "chis"
                    getMailText = "组员三"
                Case "eng"
                    getMailText = "Member (3)"
                Case "por"
                    getMailText = "Membro (3)"
            End Select
        Case "SCHOOL_INFO"
            Select Case Language
                Case "chi"
                    getMailText = "學校資料"
                Case "chis"
                    getMailText = "学校资料"
                Case "eng"
                    getMailText = "Particulars of School"
                Case "por"
                    getMailText = "Informação da Escola"
            End Select
        Case "SCHOOL_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "學校名稱"
                Case "chis"
                    getMailText = "学校名称"
                Case "eng"
                    getMailText = "Name of School"
                Case "por"
                    getMailText = "Nome da Escola"
            End Select
        Case "TEACHER_NAME"
            Select Case Language
                Case "chi"
                    getMailText = "指導老師姓名"
                Case "chis"
                    getMailText = "指导老师姓名"
                Case "eng"
                    getMailText = "Name of Supervising teacher"
                Case "por"
                    getMailText = "Nome do Professor Supervisor"
            End Select
        Case "TEACHER_CNAME"
            Select Case Language
                Case "chi"
                    getMailText = "中文"
                Case "chis"
                    getMailText = "中文"
                Case "eng"
                    getMailText = "Chinese"
                Case "por"
                    getMailText = "Chinês"
            End Select
        Case "TEACHER_PNAME"
            Select Case Language
                Case "chi"
                    getMailText = "葡文"
                Case "chis"
                    getMailText = "葡文"
                Case "eng"
                    getMailText = "Portuguese"
                Case "por"
                    getMailText = "Português"
            End Select
        Case "TEACHER_CONTACT"
            Select Case Language
                Case "chi"
                    getMailText = "指導老師聯絡方法"
                Case "chis"
                    getMailText = "指导老师联络方法"
                Case "eng"
                    getMailText = "Contact of Supervising Teacher"
                Case "por"
                    getMailText = "Contacto do Professor Supervisor"
            End Select
        Case "TEACHER_TEL"
            Select Case Language
                Case "chi"
                    getMailText = "電話"
                Case "chis"
                    getMailText = "电话"
                Case "eng"
                    getMailText = "Tel."
                Case "por"
                    getMailText = "Telefone"
            End Select
        Case "TEACHER_MAIL"
            Select Case Language
                Case "chi"
                    getMailText = "電郵"
                Case "chis"
                    getMailText = "电邮"
                Case "eng"
                    getMailText = "E-mail"
                Case "por"
                    getMailText = "E-mail"
            End Select
    End Select
End Function

 %>